part of 'page.dart';

class _PronunciationSettingsPageWloc
    extends StatefulWloc<_PronunciationSettingsPageWlocState, PronunciationSettingsPage> {
  late final bloc.PronunciationSettingsPageBloc _bloc;

  @override
  _PronunciationSettingsPageWlocState get initialState {
    return _PronunciationSettingsPageWlocStateFactory().create(
      blocState: _bloc.state,
    );
  }

  void onDialectTilePressed({
    required Dialect dialect,
  }) {
    _bloc.requestDialectChange(
      dialect: dialect,
    );
  }

  void onVoiceTilePressed({
    required TtsVoice voice,
  }) {
    _bloc.requestVoiceChange(
      voice: voice,
    );
  }

  void onSpeechRateSliderChangeEnd(double value) {
    _bloc.requestSpeechRateChange(
      normalizedSpeechRate: value,
    );
  }

  void _onBlocStateChanged(bloc.PronunciationSettingsPageBlocState blocState) {
    final updatedState = _PronunciationSettingsPageWlocStateFactory().create(
      blocState: blocState,
    );

    emit(updatedState);
  }

  @override
  void initState() {
    super.initState();

    _bloc = bloc.PronunciationSettingsPageBloc(
      ttsBloc: core_di.sl(),
      settingsBloc: core_di.sl(),
      initialize: pronunciation_settings_page_di.sl(),
      changeDialect: pronunciation_settings_page_di.sl(),
      changeSpeechRate: pronunciation_settings_page_di.sl(),
      changeVoice: pronunciation_settings_page_di.sl(),
      handlePronunciationSettingsOuterUpdate: pronunciation_settings_page_di.sl(),
    );

    _bloc.stream.listen(_onBlocStateChanged);
  }

  @override
  void dispose() {
    _bloc.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return _PronunciationSettingsPageView(
      wloc: this,
    );
  }
}
